package com.cc.seckill.web;

import com.cc.seckill.dto.Result;
import com.cc.seckill.entity.User;
import com.cc.seckill.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/user")
public class UserController {

    Logger logger = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/login",method = RequestMethod.POST)
    @ResponseBody
    public Result<String > login(@RequestBody User user, HttpSession session){

        logger.info("========start========");
        long startTime = System.currentTimeMillis();
        user = userService.Login(user.getUsername(),user.getPassword());
        if (user!=null){
            logger.error("test error");
            long endTime = System.currentTimeMillis();
            logger.debug("costTime:[{}ms]",endTime-startTime);
            logger.info("========end========");
            return new Result<>(200,"登录成功！");
        }
        else{
            logger.error("test error");
            long endTime = System.currentTimeMillis();
            logger.debug("costTime:[{}ms]",endTime-startTime);
            logger.info("========end========");
            return new Result<>(201,"登录失败！");
        }


    }

}
